package com.xiaoshuidi.cloud.module.report.utils;

import cn.hutool.core.util.ObjectUtil;
import com.xiaoshuidi.cloud.module.rooms.api.apartment.ApartmentApi;
import com.xiaoshuidi.cloud.module.rooms.api.apartment.vo.GetApartmentVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Component
public class ApartmentUtils {

    @Resource
    private ApartmentApi apartmentApi;

    public List<Long> getAllApartmentIdsByDept(){
        List<GetApartmentVO> apartmentVOS = apartmentApi.getAllApartment().getCheckedData();
        return apartmentVOS.stream().map(GetApartmentVO::getId).collect(Collectors.toList());
    }

    public List<Long> getAllIdsWhenIdsIsNull(List<Long> apartmentIds){
        if(ObjectUtil.isEmpty(apartmentIds)){
            apartmentIds = getAllApartmentIdsByDept();
        }
        return apartmentIds;
    }
}
